home *** CD-ROM | disk | FTP | other *** search
/ Mac Format 1995 June / MacFormat 25.iso / Shareware City / Developers / OutOfPhase1.1 Source / OutOfPhase Folder / CommandChooser.c < prev    next >
Text File  |  1995-01-06  |  12KB  |  428 lines

  1. /* CommandChooser.c */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    Out Of Phase:  Digital Music Synthesis on General Purpose Computers    */
  5. /*    Copyright (C) 1994  Thomas R. Lawrence                                 */
  6. /*                                                                           */
  7. /*    This program is free software; you can redistribute it and/or modify   */
  8. /*    it under the terms of the GNU General Public License as published by   */
  9. /*    the Free Software Foundation; either version 2 of the License, or      */
  10. /*    (at your option) any later version.                                    */
  11. /*                                                                           */
  12. /*    This program is distributed in the hope that it will be useful,        */
  13. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  14. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
  15. /*    GNU General Public License for more details.                           */
  16. /*                                                                           */
  17. /*    You should have received a copy of the GNU General Public License      */
  18. /*    along with this program; if not, write to the Free Software            */
  19. /*    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */
  20. /*                                                                           */
  21. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  22. /*                                                                           */
  23. /*****************************************************************************/
  24.  
  25. #include "MiscInfo.h"
  26. #include "Audit.h"
  27. #include "Debug.h"
  28. #include "Definitions.h"
  29.  
  30. #include "CommandChooser.h"
  31. #include "EventLoop.h"
  32. #include "Screen.h"
  33. #include "Memory.h"
  34. #include "SimpleButton.h"
  35. #include "StringList.h"
  36. #include "Array.h"
  37.  
  38.  
  39. #define WINXSIZE (300)
  40. #define WINYSIZE (250)
  41.  
  42. #define SCROLLX (0)
  43. #define SCROLLY (0)
  44. #define SCROLLWIDTH (WINXSIZE)
  45. #define SCROLLHEIGHT (WINYSIZE - 10 - 21 - 10)
  46.  
  47. #define CANCELBUTTONWIDTH (80)
  48. #define CANCELBUTTONHEIGHT (21)
  49. #define CANCELBUTTONY (SCROLLY + SCROLLHEIGHT + 10)
  50. #define CANCELBUTTONX ((WINXSIZE / 4) - (CANCELBUTTONWIDTH / 2))
  51.  
  52. #define OKBUTTONWIDTH (CANCELBUTTONWIDTH)
  53. #define OKBUTTONHEIGHT (CANCELBUTTONHEIGHT)
  54. #define OKBUTTONY (CANCELBUTTONY)
  55. #define OKBUTTONX (((3 * WINXSIZE) / 4) - (CANCELBUTTONWIDTH / 2))
  56.  
  57.  
  58. typedef struct
  59.     {
  60.         NoteCommands            CommandValue;
  61.     } InfoRecord;
  62.  
  63.  
  64. typedef struct
  65.     {
  66.         WinType*                    ScreenID;
  67.         StringListRec*        CommandStringList;
  68.         SimpleButtonRec*    OKButton;
  69.         SimpleButtonRec*    CancelButton;
  70.     } WindowRec;
  71.  
  72.  
  73. static InfoRecord            CommandList[] =
  74.     {
  75.         /* tempo adjustments */
  76.         {eCmdRestoreTempo},
  77.         {eCmdSetTempo},
  78.         {eCmdIncTempo},
  79.         {eCmdSweepTempoAbs},
  80.         {eCmdSweepTempoRel},
  81.  
  82.         /* stereo positioning adjustments */
  83.         {eCmdRestoreStereoPosition},
  84.         {eCmdSetStereoPosition},
  85.         {eCmdIncStereoPosition},
  86.         {eCmdSweepStereoAbs},
  87.         {eCmdSweepStereoRel},
  88.  
  89.         /* surround positioning adjustments */
  90.         {eCmdRestoreSurroundPosition},
  91.         {eCmdSetSurroundPosition},
  92.         {eCmdIncSurroundPosition},
  93.         {eCmdSweepSurroundAbs},
  94.         {eCmdSweepSurroundRel},
  95.  
  96.         /* overall volume adjustments */
  97.         {eCmdRestoreVolume},
  98.         {eCmdSetVolume},
  99.         {eCmdIncVolume},
  100.         {eCmdSweepVolumeAbs},
  101.         {eCmdSweepVolumeRel},
  102.  
  103.         /* default release point adjustment values */
  104.         {eCmdRestoreReleasePoint1},
  105.         {eCmdSetReleasePoint1},
  106.         {eCmdIncReleasePoint1},
  107.         {eCmdReleasePointOrigin1},
  108.         {eCmdSweepReleaseAbs1},
  109.         {eCmdSweepReleaseRel1},
  110.  
  111.         {eCmdRestoreReleasePoint2},
  112.         {eCmdSetReleasePoint2},
  113.         {eCmdIncReleasePoint2},
  114.         {eCmdReleasePointOrigin2},
  115.         {eCmdSweepReleaseAbs2},
  116.         {eCmdSweepReleaseRel2},
  117.  
  118.         /* set the default accent values */
  119.         {eCmdRestoreAccent1},
  120.         {eCmdSetAccent1},
  121.         {eCmdIncAccent1},
  122.         {eCmdSweepAccentAbs1},
  123.         {eCmdSweepAccentRel1},
  124.  
  125.         {eCmdRestoreAccent2},
  126.         {eCmdSetAccent2},
  127.         {eCmdIncAccent2},
  128.         {eCmdSweepAccentAbs2},
  129.         {eCmdSweepAccentRel2},
  130.  
  131.         {eCmdRestoreAccent3},
  132.         {eCmdSetAccent3},
  133.         {eCmdIncAccent3},
  134.         {eCmdSweepAccentAbs3},
  135.         {eCmdSweepAccentRel3},
  136.  
  137.         {eCmdRestoreAccent4},
  138.         {eCmdSetAccent4},
  139.         {eCmdIncAccent4},
  140.         {eCmdSweepAccentAbs4},
  141.         {eCmdSweepAccentRel4},
  142.  
  143.         /* set pitch displacement depth adjustment */
  144.         {eCmdRestorePitchDispDepth},
  145.         {eCmdSetPitchDispDepth},
  146.         {eCmdIncPitchDispDepth},
  147.         {eCmdSweepPitchDispDepthAbs},
  148.         {eCmdSweepPitchDispDepthRel},
  149.  
  150.         /* set pitch displacement rate adjustment */
  151.         {eCmdRestorePitchDispRate},
  152.         {eCmdSetPitchDispRate},
  153.         {eCmdIncPitchDispRate},
  154.         {eCmdSweepPitchDispRateAbs},
  155.         {eCmdSweepPitchDispRateRel},
  156.  
  157.         /* set pitch displacement start point, same way as release point */
  158.         {eCmdRestorePitchDispStart},
  159.         {eCmdSetPitchDispStart},
  160.         {eCmdIncPitchDispStart},
  161.         {eCmdPitchDispStartOrigin},
  162.         {eCmdSweepPitchDispStartAbs},
  163.         {eCmdSweepPitchDispStartRel},
  164.  
  165.         /* hurry up adjustment */
  166.         {eCmdRestoreHurryUp},
  167.         {eCmdSetHurryUp},
  168.         {eCmdIncHurryUp},
  169.         {eCmdSweepHurryUpAbs},
  170.         {eCmdSweepHurryUpRel},
  171.  
  172.         /* default detune */
  173.         {eCmdRestoreDetune},
  174.         {eCmdSetDetune},
  175.         {eCmdIncDetune},
  176.         {eCmdDetuneMode},
  177.         {eCmdSweepDetuneAbs},
  178.         {eCmdSweepDetuneRel},
  179.  
  180.         /* default early/late adjust */
  181.         {eCmdRestoreEarlyLateAdjust},
  182.         {eCmdSetEarlyLateAdjust},
  183.         {eCmdIncEarlyLateAdjust},
  184.         {eCmdSweepEarlyLateAbs},
  185.         {eCmdSweepEarlyLateRel},
  186.  
  187.         /* default duration adjust */
  188.         {eCmdRestoreDurationAdjust},
  189.         {eCmdSetDurationAdjust},
  190.         {eCmdIncDurationAdjust},
  191.         {eCmdSweepDurationAbs},
  192.         {eCmdSweepDurationRel},
  193.         {eCmdDurationAdjustMode},
  194.  
  195.         /* set the meter.  this is used by the editor for placing measure bars. */
  196.         /* measuring restarts immediately after this command */
  197.         {eCmdSetMeter},
  198.         /* set the measure number. */
  199.         {eCmdSetMeasureNumber},
  200.  
  201.         /* transpose controls */
  202.         {eCmdSetTranspose},
  203.         {eCmdAdjustTranspose},
  204.  
  205.         /* set and adjust effect control parameters */
  206.         {eCmdSetEffectParam1},
  207.         {eCmdIncEffectParam1},
  208.         {eCmdSweepEffectParamAbs1},
  209.         {eCmdSweepEffectParamRel1},
  210.  
  211.         {eCmdSetEffectParam2},
  212.         {eCmdIncEffectParam2},
  213.         {eCmdSweepEffectParamAbs2},
  214.         {eCmdSweepEffectParamRel2},
  215.  
  216.         {eCmdSetEffectParam3},
  217.         {eCmdIncEffectParam3},
  218.         {eCmdSweepEffectParamAbs3},
  219.         {eCmdSweepEffectParamRel3},
  220.  
  221.         {eCmdSetEffectParam4},
  222.         {eCmdIncEffectParam4},
  223.         {eCmdSweepEffectParamAbs4},
  224.         {eCmdSweepEffectParamRel4},
  225.  
  226.         /* track effect processor enable switch */
  227.         {eCmdTrackEffectEnable},
  228.  
  229.         /* set and adjust global score effect control parameters */
  230.         {eCmdSetScoreEffectParam1},
  231.         {eCmdIncScoreEffectParam1},
  232.         {eCmdSweepScoreEffectParamAbs1},
  233.         {eCmdSweepScoreEffectParamRel1},
  234.  
  235.         {eCmdSetScoreEffectParam2},
  236.         {eCmdIncScoreEffectParam2},
  237.         {eCmdSweepScoreEffectParamAbs2},
  238.         {eCmdSweepScoreEffectParamRel2},
  239.  
  240.         {eCmdSetScoreEffectParam3},
  241.         {eCmdIncScoreEffectParam3},
  242.         {eCmdSweepScoreEffectParamAbs3},
  243.         {eCmdSweepScoreEffectParamRel3},
  244.  
  245.         {eCmdSetScoreEffectParam4},
  246.         {eCmdIncScoreEffectParam4},
  247.         {eCmdSweepScoreEffectParamAbs4},
  248.         {eCmdSweepScoreEffectParamRel4},
  249.  
  250.         /* text marker in the score */
  251.         {eCmdMarker}
  252.     };
  253. #define CommandListLength (sizeof(CommandList) / sizeof(CommandList[0]))
  254.  
  255.  
  256. /* this thing redraws our window */
  257. static void                RedrawOurWindow(WindowRec* Window)
  258.     {
  259.         CheckPtrExistence(Window);
  260.         RedrawStringList(Window->CommandStringList);
  261.         RedrawSimpleButton(Window->OKButton);
  262.         RedrawSimpleButton(Window->CancelButton);
  263.     }
  264.  
  265.  
  266. /* display a scrolling list and let the user choose a command.  if the user cancels */
  267. /* then is returns False, otherwise True. */
  268. MyBoolean                    ChooseCommandFromList(NoteCommands* Command)
  269.     {
  270.         WindowRec*            Window;
  271.         long                        Scan;
  272.         MyBoolean                LoopFlag;
  273.         MyBoolean                DoItFlag EXECUTE(= -424);
  274.  
  275.         ERROR(Command == NIL,PRERR(ForceAbort,"ChooseCommandFromList:  Command == NIL"));
  276.         Window = (WindowRec*)AllocPtrCanFail(sizeof(WindowRec),
  277.             "ChooseCommandFromList WindowRec");
  278.         if (Window == NIL)
  279.             {
  280.              FailurePoint1:
  281.                 return False;
  282.             }
  283.         Window->ScreenID = MakeNewWindow(eModelessDialogWindow,eWindowNotClosable,
  284.             eWindowNotZoomable,eWindowNotResizable,DialogLeftEdge(WINXSIZE),
  285.             DialogTopEdge(WINYSIZE),WINXSIZE,WINYSIZE,(void (*)(void*))&RedrawOurWindow,Window);
  286.         if (Window->ScreenID == NIL)
  287.             {
  288.              FailurePoint2:
  289.                 ReleasePtr((char*)Window);
  290.                 goto FailurePoint1;
  291.             }
  292.         SetWindowName(Window->ScreenID,"Command Chooser");
  293.         Window->OKButton = NewSimpleButton(Window->ScreenID,"OK",OKBUTTONX,OKBUTTONY,
  294.             OKBUTTONWIDTH,OKBUTTONHEIGHT);
  295.         if (Window->OKButton == NIL)
  296.             {
  297.              FailurePoint3:
  298.                 KillWindow(Window->ScreenID);
  299.                 goto FailurePoint2;
  300.             }
  301.         SetDefaultButtonState(Window->OKButton,True);
  302.         Window->CancelButton = NewSimpleButton(Window->ScreenID,"Cancel",CANCELBUTTONX,
  303.             CANCELBUTTONY,CANCELBUTTONWIDTH,CANCELBUTTONHEIGHT);
  304.         if (Window->CancelButton == NIL)
  305.             {
  306.              FailurePoint4:
  307.                 DisposeSimpleButton(Window->OKButton);
  308.                 goto FailurePoint3;
  309.             }
  310.         Window->CommandStringList = NewStringList(Window->ScreenID,SCROLLX,SCROLLY,
  311.             SCROLLWIDTH,SCROLLHEIGHT,GetScreenFont(),9,StringListDontAllowMultipleSelection,
  312.             "Choose a Command");
  313.         if (Window->CommandStringList == NIL)
  314.             {
  315.              FailurePoint5:
  316.                 DisposeSimpleButton(Window->CancelButton);
  317.                 goto FailurePoint4;
  318.             }
  319.         EnableStringList(Window->CommandStringList);
  320.         for (Scan = 0; Scan < CommandListLength; Scan += 1)
  321.             {
  322.                 if (!InsertStringListElement(Window->CommandStringList,
  323.                     GetCommandName(CommandList[Scan].CommandValue),NIL,&(CommandList[Scan]),False))
  324.                     {
  325.                      FailurePoint6:
  326.                         DisposeStringList(Window->CommandStringList);
  327.                         goto FailurePoint5;
  328.                     }
  329.             }
  330.  
  331.         LoopFlag = True;
  332.         while (LoopFlag)
  333.             {
  334.                 OrdType                            X;
  335.                 OrdType                            Y;
  336.                 ModifierFlags                Modifiers;
  337.                 struct MenuItemType*    MenuItem;
  338.                 char                                KeyPress;
  339.  
  340.                 switch (GetAnEvent(&X,&Y,&Modifiers,NIL,&MenuItem,&KeyPress))
  341.                     {
  342.                         default:
  343.                             break;
  344.                         case eCheckCursor:
  345.                             SetArrowCursor();
  346.                             break;
  347.                         case eKeyPressed:
  348.                             if (KeyPress == 13)
  349.                                 {
  350.                                     FlashButton(Window->OKButton);
  351.                                     DoItFlag = True;
  352.                                     LoopFlag = False;
  353.                                 }
  354.                             else if (KeyPress == eCancelKey)
  355.                                 {
  356.                                     FlashButton(Window->CancelButton);
  357.                                     DoItFlag = False;
  358.                                     LoopFlag = False;
  359.                                 }
  360.                             break;
  361.                         case eMouseDown:
  362.                             if (SimpleButtonHitTest(Window->OKButton,X,Y))
  363.                                 {
  364.                                     if (SimpleButtonMouseDown(Window->OKButton,X,Y,NIL,NIL))
  365.                                         {
  366.                                             DoItFlag = True;
  367.                                             LoopFlag = False;
  368.                                         }
  369.                                 }
  370.                             else if (SimpleButtonHitTest(Window->CancelButton,X,Y))
  371.                                 {
  372.                                     if (SimpleButtonMouseDown(Window->CancelButton,X,Y,NIL,NIL))
  373.                                         {
  374.                                             DoItFlag = False;
  375.                                             LoopFlag = False;
  376.                                         }
  377.                                 }
  378.                             else if (StringListHitTest(Window->CommandStringList,X,Y))
  379.                                 {
  380.                                     if (StringListMouseDown(Window->CommandStringList,X,Y,Modifiers))
  381.                                         {
  382.                                             DoItFlag = True;
  383.                                             LoopFlag = False;
  384.                                         }
  385.                                 }
  386.                             break;
  387.                     }
  388.             }
  389.         ERROR((DoItFlag != True) && (DoItFlag != False),PRERR(ForceAbort,
  390.             "ChooseCommandFromList:  DoItFlag is neither true nor false"));
  391.  
  392.         if (DoItFlag)
  393.             {
  394.                 ArrayRec*                SelectionList;
  395.  
  396.                 /* find out what thing was clicked */
  397.                 SelectionList = GetListOfSelectedItems(Window->CommandStringList);
  398.                 if (SelectionList != NIL)
  399.                     {
  400.                         /* see if there really is a selection */
  401.                         if (ArrayGetLength(SelectionList) > 0)
  402.                             {
  403.                                 InfoRecord*            Info;
  404.  
  405.                                 /* recover the info record */
  406.                                 Info = (InfoRecord*)ArrayGetElement(SelectionList,0);
  407.                                 *Command = Info->CommandValue;
  408.                             }
  409.                          else
  410.                             {
  411.                                 DoItFlag = False; /* there wasn't a real selection, so cancel */
  412.                             }
  413.                         DisposeArray(SelectionList);
  414.                     }
  415.                  else
  416.                     {
  417.                         DoItFlag = False; /* out of memory, so cancel operation */
  418.                     }
  419.             }
  420.  
  421.         DisposeStringList(Window->CommandStringList);
  422.         DisposeSimpleButton(Window->OKButton);
  423.         DisposeSimpleButton(Window->CancelButton);
  424.         KillWindow(Window->ScreenID);
  425.         ReleasePtr((char*)Window);
  426.         return DoItFlag;
  427.     }
  428.